package com.ruoyi.project.interface_log.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.interface_log.domain.InterfaceLog;
import com.ruoyi.project.interface_log.service.IInterfaceLogService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 日志表Controller
 * 
 * @author ruoyi
 * @date 2023-08-22
 */
@Controller
@RequestMapping("/log/log")
public class InterfaceLogController extends BaseController
{
    private String prefix = "log/log";

    @Autowired
    private IInterfaceLogService interfaceLogService;

    @GetMapping()
    public String log()
    {
        return prefix + "/log";
    }

    /**
     * 查询日志表列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(InterfaceLog interfaceLog)
    {
        startPage();
        List<InterfaceLog> list = interfaceLogService.selectInterfaceLogList(interfaceLog);
        return getDataTable(list);
    }

    /**
     * 导出日志表列表
     */
    @Log(title = "日志表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(InterfaceLog interfaceLog)
    {
        List<InterfaceLog> list = interfaceLogService.selectInterfaceLogList(interfaceLog);
        ExcelUtil<InterfaceLog> util = new ExcelUtil<InterfaceLog>(InterfaceLog.class);
        return util.exportExcel(list, "日志表数据");
    }

    /**
     * 新增日志表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存日志表
     */
    @Log(title = "日志表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(InterfaceLog interfaceLog)
    {
        return toAjax(interfaceLogService.insertInterfaceLog(interfaceLog));
    }

    /**
     * 修改日志表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        InterfaceLog interfaceLog = interfaceLogService.selectInterfaceLogById(id);
        mmap.put("interfaceLog", interfaceLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存日志表
     */
    @Log(title = "日志表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(InterfaceLog interfaceLog)
    {
        return toAjax(interfaceLogService.updateInterfaceLog(interfaceLog));
    }

    /**
     * 删除日志表
     */
    @Log(title = "日志表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(interfaceLogService.deleteInterfaceLogByIds(ids));
    }
}
